﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WcfGeebaServer.ContentManage;
using WcfGeebaServer.DBDAL;

namespace WcfGeebaServer.Users
{
    [Serializable]
    public class Member : User
    {
        #region Fields

        private string password;
        private bool isActive;
        private List<Member> friends;
        private int threadCount;
        private bool isBanned;

        #endregion

        #region DataMembers

        /// <summary>
        /// Internal Property for password
        /// </summary>
        internal string Password
        {
            get { return password; }
            set { password = value; }
        }
        public bool IsActive
        {
            get { return isActive; }
            private set { this.isActive = value; }
        }
        public List<Member> Friends
        {
            get { return friends; }
            private set { friends = value; }
        }

        public int ThreadCount
        {
            get { return getThreadCount(); }
            private set { threadCount = value; }
        }

        public bool IsBanned
        {
            get { return GetBanField(); }
            private set { this.isBanned = value; }
        }

        #endregion

        #region Ctors

        public Member(string username, string password, bool isActive) : base(username)
        {
            this.password = password;
            this.IsActive = isActive;
            this.Friends = new List<Member>();
            this.UserType = Users.UserType.Member;
            this.threadCount = 0;
        }

        #endregion

        #region Methods

        public bool isLawBreaker()
        {
            return MemberDA.getMemberDA().isLawBreaker(this.Username);
        }

        public bool setIsActive(bool isActive)
        {
            if (this.isActive != isActive)
            {
                bool res = MemberDA.getMemberDA().setIsActive(this.Username, isActive);
                if (res)
                {
                    this.isActive = isActive;
                }
                return res;
            }
            return true;
        }

        public bool BanMember()
        {
            if (this.isBanned != true)
            {
                bool res = MemberDA.getMemberDA().BanMember(this.Username);
                if (res)
                {
                    this.isBanned = true;
                }
                return res;

            }
            return true;
        }

        private int getThreadCount()
        {
            return MemberDA.getMemberDA().getThreadCount(this.Username);
        }

        private bool GetBanField()
        {
            return MemberDA.getMemberDA().IsBanned(this.Username);
        }




        #endregion
    }
}
